﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.OracleClient;

namespace Portal.Logic
{
    public class TRXN_Logic
    {
        #region 执行查
        public DataTable GetTable(string sql, string ConnectionString, params OracleParameter[] par)
        {
            using (OracleConnection Conn = new OracleConnection(ConfigurationManager.ConnectionStrings[ConnectionString].ToString()))
            {
                if (Conn.State == ConnectionState.Closed)
                {
                    Conn.Open();
                }
                OracleDataAdapter OracleDataAdapter = new OracleDataAdapter(sql, Conn);
                DataTable DataTable = new DataTable();
                foreach (OracleParameter item in par)
                {
                    OracleDataAdapter.SelectCommand.Parameters.Add(item);
                }
                OracleDataAdapter.Fill(DataTable);
                Conn.Close();
                Conn.Dispose();
                return DataTable;
            }
        }
        #endregion

        #region 执行增删改
        public int Extec(string sql, string ConnectionString, params OracleParameter[] par)
        {
            using (OracleConnection Conn = new OracleConnection(ConfigurationManager.ConnectionStrings[ConnectionString].ToString()))
            {
                if (Conn.State == ConnectionState.Closed)
                {
                    Conn.Open();
                }
                OracleCommand OracleCommand = new OracleCommand();
                OracleCommand.CommandText = sql;
                OracleCommand.Connection = Conn;
                foreach (OracleParameter item in par)
                {
                    OracleCommand.Parameters.Add(item);
                }
                int i = 0;
                i = OracleCommand.ExecuteNonQuery();
                Conn.Close();
                Conn.Dispose();
                return i;
            }
        }
        #endregion

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="Where"></param>
        /// <returns></returns>
        public string GetLevelUser(string Where)
        {
            string RealName = "";
            DataTable dt = GetTable("SELECT * FROM TRXN_LEVELUSER WHERE " + Where, "BusinessDB");
            if (dt.Rows.Count>0)
            {
                RealName = dt.Rows[0]["REALNAME"].ToString();
            }
            return RealName;
        }
    }
}
